x = int(input())
def is_simple(x):
    for i in range(2, x):
        if i != x and x % i == 0:
            return 0
    return 1
if is_simple(x):
    print(x)
else:
    if x > 9999 or x < 1000:
        print(0)
    x_ = []
    for i in range(len(str(x))):
        x_ += str(x)[i]
    m = []
    for i in range(3):
        if is_simple(int(x_[i] + x_[i+1])):
            m.append(int(x_[i] + x_[i+1]))
    mx = 0
    if len(m) != 0:
        for i in range(2):
            if m[i] > m[i+1]:
                mx = m[i]
    if is_simple(int(x_[0] + x_[1] + x_[2])):
        mx = int(x_[0] + x_[1] + x_[2])
    if is_simple(int(x_[1] + x_[2] + x_[3])):
        if is_simple(int(x_[0] + x_[1] + x_[2])):
            if int(x_[0] + x_[1] + x_[2]) > int(x_[1] + x_[2] + x_[3]):
                mx = int(x_[0] + x_[1] + x_[2])
            else:
                mx = int(x_[1] + x_[2] + x_[3])
        else:
            mx = int(x_[1] + x_[2] + x_[3])
    print(mx)
